<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>The Wiring</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
function togglePopup(material_id) {
  var popup = document.getElementById(material_id);
  popup.classList.toggle("show");
}
</script>

<link href="../docs-assets/Popups.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html"><img src="../docs-assets/Inform.png" height=72> </a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=0> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=0> inweb</a></li>
<li><a href="https://github.com/ganelson/intest"><img src="../docs-assets/github.png" height=0> intest</a></li>
</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'The Wiring' generated by inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../intern.html">Inter Modules</a></li><li><a href="index.html">bytecode</a></li><li><a href="index.html#2">Chapter 2: The Trees</a></li><li><b>The Wiring</b></li></ul></div>
<p class="purpose">Wiring symbols in one package to meanings in another, and via plugs and sockets even to packages in trees not yet loaded in.</p>

<ul class="toc"><li><a href="2-tw2.html#SP1">&#167;1. Wiring to symbols</a></li><li><a href="2-tw2.html#SP7">&#167;7. Wiring to names</a></li><li><a href="2-tw2.html#SP8">&#167;8. Plugs and sockets</a></li></ul><hr class="tocbar">

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. Wiring to symbols.</b>"Wiring" is used to allow symbols in one package to refer to meanings defined
in another. Since meanings are defined by symbols, this is done by allowing a
symbol in one package to connect to a symbol in the other.
</p>

<p class="commentary">For example, suppose the variable <span class="extract"><span class="extract-syntax">draconia</span></span> is defined in package <span class="extract"><span class="extract-syntax">Y</span></span>, but
needs to be referred to in <span class="extract"><span class="extract-syntax">X</span></span>. Then <span class="extract"><span class="extract-syntax">X</span></span> will also contain a symbol <span class="extract"><span class="extract-syntax">draconia</span></span>,
but rather than being defined there, it is wired to the one in <span class="extract"><span class="extract-syntax">Y</span></span>:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    +-----------------+        +-------------------------------+</span>
<span class="plain-syntax">    | </span><span class="identifier-syntax">Package</span><span class="plain-syntax"> </span><span class="identifier-syntax">X</span><span class="plain-syntax">       |        | </span><span class="identifier-syntax">Package</span><span class="plain-syntax"> </span><span class="identifier-syntax">Y</span><span class="plain-syntax">                     |</span>
<span class="plain-syntax">    |                 |        |                               |</span>
<span class="plain-syntax">    | </span><span class="identifier-syntax">draconia</span><span class="plain-syntax"> ~~~~~~~~~~~~+~~~~~&gt; </span><span class="identifier-syntax">draconia</span><span class="plain-syntax">                    |</span>
<span class="plain-syntax">    +-----------------+   /    | .....                         |</span>
<span class="plain-syntax">                          |    | </span><span class="identifier-syntax">variable</span><span class="plain-syntax"> </span><span class="identifier-syntax">K_int32</span><span class="plain-syntax"> </span><span class="identifier-syntax">draconia</span><span class="plain-syntax"> = </span><span class="constant-syntax">3</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">                          |    +-------------------------------+</span>
<span class="plain-syntax">    +-----------------+   |</span>
<span class="plain-syntax">    | </span><span class="identifier-syntax">Package</span><span class="plain-syntax"> </span><span class="identifier-syntax">W</span><span class="plain-syntax">       |   |</span>
<span class="plain-syntax">    |                 |   |</span>
<span class="plain-syntax">    | </span><span class="identifier-syntax">draconia</span><span class="plain-syntax"> ~~~~~~~~~~~/</span>
<span class="plain-syntax">    +-----------------+</span>
</pre>
<p class="commentary">We write <span class="extract"><span class="extract-syntax">A ~~&gt; B</span></span> as a picturesque notation; the wiring is supposed to look
coiled, or something like that. As this diagram shows, it can happen that more
than one symbol is wired to the same destination; but each individual symbol
can wire to at most one other.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">wiring_data</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">connects_to</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">wants_to_connect_to</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">incoming_wire_count</span><span class="plain-syntax">;</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">wiring_data</span><span class="plain-syntax">;</span>

<span class="reserved-syntax">wiring_data</span><span class="plain-syntax"> </span><span class="function-syntax">Wiring::new_wiring_data</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">Wiring::new_wiring_data</span></span>:<br/>Symbols - <a href="2-sym.html#SP2">&#167;2</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">S</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">wiring_data</span><span class="plain-syntax"> </span><span class="identifier-syntax">wd</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">wd</span><span class="plain-syntax">.</span><span class="element-syntax">connects_to</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">wd</span><span class="plain-syntax">.</span><span class="element-syntax">wants_to_connect_to</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">wd</span><span class="plain-syntax">.</span><span class="element-syntax">incoming_wire_count</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">wd</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<ul class="endnotetexts"><li>The structure wiring_data is private to this section.</li></ul>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. </b>If <span class="extract"><span class="extract-syntax">A ~~&gt; B</span></span> then <span class="extract"><span class="extract-syntax">A</span></span> is said to be "wired", and <span class="extract"><span class="extract-syntax">B</span></span> is what it is wired to.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Wiring::is_wired</span><button class="popup" onclick="togglePopup('usagePopup2')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup2">Usage of <span class="code-font"><span class="function-syntax">Wiring::is_wired</span></span>:<br/><a href="2-tw2.html#SP12">&#167;12</a>, <a href="2-tw2.html#SP15">&#167;15</a>, <a href="2-tw2.html#SP17">&#167;17</a><br/>Symbols - <a href="2-sym.html#SP18">&#167;18</a><br/>Transmigration - <a href="2-trn.html#SP5_2_2">&#167;5.2.2</a>, <a href="2-trn.html#SP6">&#167;6</a><br/>Inter in Binary Files - <a href="3-iibf.html#SP10_2_4">&#167;10.2.4</a><br/>Inter in Text Files - <a href="3-iitf.html#SP10">&#167;10</a><br/>Verifying Inter - <a href="3-vi.html#SP1_2_1">&#167;1.2.1</a><br/>The Plug Construct - <a href="6-tpc.html#SP3">&#167;3</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">S</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-tw2.html#SP2" class="function-link"><span class="function-syntax">Wiring::wired_to</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="function-syntax">Wiring::wired_to</span><button class="popup" onclick="togglePopup('usagePopup3')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup3">Usage of <span class="code-font"><span class="function-syntax">Wiring::wired_to</span></span>:<br/><a href="2-tw2.html#SP6">&#167;6</a>, <a href="2-tw2.html#SP12">&#167;12</a>, <a href="2-tw2.html#SP17">&#167;17</a><br/>Symbols Tables - <a href="2-st.html#SP16_1_1">&#167;16.1.1</a><br/>Inter in Binary Files - <a href="3-iibf.html#SP10_2_4">&#167;10.2.4</a><br/>The Plug Construct - <a href="6-tpc.html#SP3">&#167;3</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">S</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">S</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">S</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">wiring</span><span class="plain-syntax">.</span><span class="element-syntax">connects_to</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. </b>This metaphor only goes so far: wiring is directional &mdash; if A is wired to B then
B is not by virtue of that wired to A; and indeed, circuits are forbidden.
</p>

<p class="commentary">Nevertheless it does happen that we have a sequence of symbols each wired to
the next: <span class="extract"><span class="extract-syntax">A ~~&gt; B ~~&gt; C ~~&gt; ... ~~&gt; X</span></span>. Following such cables, we must always
reach an end. On all these symbols, <a href="2-tw2.html#SP3" class="internal">Wiring::cable_end</a> returns <span class="extract"><span class="extract-syntax">X</span></span>.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="function-syntax">Wiring::cable_end</span><button class="popup" onclick="togglePopup('usagePopup4')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup4">Usage of <span class="code-font"><span class="function-syntax">Wiring::cable_end</span></span>:<br/><a href="2-tw2.html#SP6">&#167;6</a>, <a href="2-tw2.html#SP12">&#167;12</a><br/>Symbols Tables - <a href="2-st.html#SP5_2">&#167;5.2</a>, <a href="2-st.html#SP13">&#167;13</a><br/>Transmigration - <a href="2-trn.html#SP3_5">&#167;3.5</a>, <a href="2-trn.html#SP3_5_1">&#167;3.5.1</a>, <a href="2-trn.html#SP5_2_2">&#167;5.2.2</a>, <a href="2-trn.html#SP6">&#167;6</a><br/>Inter in Text Files - <a href="3-iitf.html#SP10">&#167;10</a><br/>Verifying Inter - <a href="3-vi.html#SP1_2_1">&#167;1.2.1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">S</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">S</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">S</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">wiring</span><span class="plain-syntax">.</span><span class="element-syntax">connects_to</span><span class="plain-syntax">)) </span><span class="identifier-syntax">S</span><span class="plain-syntax"> = </span><span class="identifier-syntax">S</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">wiring</span><span class="plain-syntax">.</span><span class="element-syntax">connects_to</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">S</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. </b>In general, we have no means of following wiring backwards: that is, given
<span class="extract"><span class="extract-syntax">B</span></span>, we cannot easily find all the <span class="extract"><span class="extract-syntax">A</span></span> such that <span class="extract"><span class="extract-syntax">A ~~&gt; B</span></span>. What we can do is
to say how many such <span class="extract"><span class="extract-syntax">A</span></span> exist, and it's useful to know when this count is 0,
because then we may be able safely to delete <span class="extract"><span class="extract-syntax">B</span></span> as no longer needed.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Wiring::has_no_incoming_connections</span><span class="plain-syntax">(</span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">S</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">S</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">S</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">wiring</span><span class="plain-syntax">.</span><span class="element-syntax">incoming_wire_count</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. </b>Wiring must be performed with this function, or the incoming wire count may
be broken.
</p>

<p class="commentary">Metadata constants cannot be wired (or wired to), because they by definition
describe content in the current package. They are self-contained, and the meaning
of the program must not be changed by their removal.
</p>

<p class="commentary">Note that <span class="extract"><span class="extract-syntax">S</span></span> may be unwired by calling <span class="extract"><span class="extract-syntax">Wiring::wire_to(S, NULL)</span></span>.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Wiring::wire_to</span><button class="popup" onclick="togglePopup('usagePopup5')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup5">Usage of <span class="code-font"><span class="function-syntax">Wiring::wire_to</span></span>:<br/><a href="2-tw2.html#SP6">&#167;6</a>, <a href="2-tw2.html#SP7">&#167;7</a>, <a href="2-tw2.html#SP13">&#167;13</a>, <a href="2-tw2.html#SP16">&#167;16</a><br/>Symbols Tables - <a href="2-st.html#SP16_1_2">&#167;16.1.2</a>, <a href="2-st.html#SP21">&#167;21</a><br/>Transmigration - <a href="2-trn.html#SP3_5_1">&#167;3.5.1</a>, <a href="2-trn.html#SP5_2_2_1">&#167;5.2.2.1</a>, <a href="2-trn.html#SP5_2_2_2">&#167;5.2.2.2</a>, <a href="2-trn.html#SP5_2_2_3">&#167;5.2.2.3</a>, <a href="2-trn.html#SP6_1">&#167;6.1</a><br/>Inter in Binary Files - <a href="3-iibf.html#SP10_1_4">&#167;10.1.4</a><br/>Inter in Text Files - <a href="3-iitf.html#SP7_1">&#167;7.1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">S</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">T</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">S</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"null symbol cannot be wired"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><a href="2-sym.html#SP10" class="function-link"><span class="function-syntax">InterSymbol::is_metadata_key</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">)) || ((</span><span class="identifier-syntax">T</span><span class="plain-syntax">) &amp;&amp; (</span><a href="2-sym.html#SP10" class="function-link"><span class="function-syntax">InterSymbol::is_metadata_key</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">T</span><span class="plain-syntax">))))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"metadata keys cannot be wired"</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    </span><span class="comment-syntax"> if S ~~&gt; T already, return now, and do not increment the count for T</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">S</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">wiring</span><span class="plain-syntax">.</span><span class="element-syntax">connects_to</span><span class="plain-syntax"> == </span><span class="identifier-syntax">T</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="comment-syntax"> if S ~~&gt; U for some other U, decrement the count for U</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">S</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">wiring</span><span class="plain-syntax">.</span><span class="element-syntax">connects_to</span><span class="plain-syntax">) </span><span class="identifier-syntax">S</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">wiring</span><span class="plain-syntax">.</span><span class="element-syntax">connects_to</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">wiring</span><span class="plain-syntax">.</span><span class="element-syntax">incoming_wire_count</span><span class="plain-syntax">--;</span>

<span class="plain-syntax">    </span><span class="comment-syntax"> make S ~~&gt; T, and increment the count for T</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">S</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">wiring</span><span class="plain-syntax">.</span><span class="element-syntax">connects_to</span><span class="plain-syntax"> = </span><span class="identifier-syntax">T</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">S</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">wiring</span><span class="plain-syntax">.</span><span class="element-syntax">wants_to_connect_to</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">T</span><span class="plain-syntax">) </span><span class="identifier-syntax">T</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">wiring</span><span class="plain-syntax">.</span><span class="element-syntax">incoming_wire_count</span><span class="plain-syntax">++;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">INTER_SYMBOLS</span><span class="plain-syntax">, </span><span class="string-syntax">"Wired $3 to $3\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">S</span><span class="plain-syntax">, </span><span class="identifier-syntax">T</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="2-tw2.html#SP5_1" class="named-paragraph-link"><span class="named-paragraph">Throw an internal error if a circuit was made</span><span class="named-paragraph-number">5.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">c</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">W</span><span class="plain-syntax"> = </span><span class="identifier-syntax">S</span><span class="plain-syntax">; </span><span class="identifier-syntax">W</span><span class="plain-syntax">; </span><span class="identifier-syntax">W</span><span class="plain-syntax"> = </span><span class="identifier-syntax">W</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">wiring</span><span class="plain-syntax">.</span><span class="element-syntax">connects_to</span><span class="plain-syntax">, </span><span class="identifier-syntax">c</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">c</span><span class="plain-syntax"> == </span><span class="constant-syntax">100</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">c</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">W</span><span class="plain-syntax"> = </span><span class="identifier-syntax">S</span><span class="plain-syntax">; ((</span><span class="identifier-syntax">W</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">c</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">20</span><span class="plain-syntax">)); </span><span class="identifier-syntax">W</span><span class="plain-syntax"> = </span><span class="identifier-syntax">W</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">wiring</span><span class="plain-syntax">.</span><span class="element-syntax">connects_to</span><span class="plain-syntax">, </span><span class="identifier-syntax">c</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"%d. %S\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">c</span><span class="plain-syntax">, </span><a href="2-sym.html#SP19" class="function-link"><span class="function-syntax">InterSymbol::identifier</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">W</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"..."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"probably made a circuit in wiring"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP5_1" class="paragraph-anchor"></a><b>&#167;5.1. </b>In normal use, wiring never exceeds a cable length of about 4, so 1000 is
plenty here.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Throw an internal error if a circuit was made</span><span class="named-paragraph-number">5.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">c</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">W</span><span class="plain-syntax"> = </span><span class="identifier-syntax">S</span><span class="plain-syntax">; </span><span class="identifier-syntax">W</span><span class="plain-syntax">; </span><span class="identifier-syntax">W</span><span class="plain-syntax"> = </span><span class="identifier-syntax">W</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">wiring</span><span class="plain-syntax">.</span><span class="element-syntax">connects_to</span><span class="plain-syntax">, </span><span class="identifier-syntax">c</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">c</span><span class="plain-syntax"> == </span><span class="constant-syntax">1000</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">STDERR</span><span class="plain-syntax">, </span><span class="string-syntax">"Wiring caused circuit:\n"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">c</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">W</span><span class="plain-syntax"> = </span><span class="identifier-syntax">S</span><span class="plain-syntax">; ((</span><span class="identifier-syntax">W</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">c</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">20</span><span class="plain-syntax">)); </span><span class="identifier-syntax">W</span><span class="plain-syntax"> = </span><span class="identifier-syntax">W</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">wiring</span><span class="plain-syntax">.</span><span class="element-syntax">connects_to</span><span class="plain-syntax">, </span><span class="identifier-syntax">c</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">STDERR</span><span class="plain-syntax">, </span><span class="string-syntax">"%d. %S\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">c</span><span class="plain-syntax">, </span><a href="2-sym.html#SP19" class="function-link"><span class="function-syntax">InterSymbol::identifier</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">W</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">STDERR</span><span class="plain-syntax">, </span><span class="string-syntax">"..."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"made a circuit in wiring"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-tw2.html#SP5">&#167;5</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>&#167;6. </b>If we do have a cable <span class="extract"><span class="extract-syntax">A ~~&gt; B ~~&gt; ... ~~&gt; X</span></span>, we can "shorten" this from <span class="extract"><span class="extract-syntax">A</span></span>
by making <span class="extract"><span class="extract-syntax">A ~~&gt; X</span></span> directly. It will still be the case that <span class="extract"><span class="extract-syntax">B ~~&gt; ... ~~&gt; X</span></span>,
of course. Assuming <span class="extract"><span class="extract-syntax">B</span></span> is not <span class="extract"><span class="extract-syntax">X</span></span>, the incoming count for <span class="extract"><span class="extract-syntax">B</span></span> will decrement
and that for <span class="extract"><span class="extract-syntax">X</span></span> increment.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Wiring::shorten_wiring</span><span class="plain-syntax">(</span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">S</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">E</span><span class="plain-syntax"> = </span><a href="2-tw2.html#SP3" class="function-link"><span class="function-syntax">Wiring::cable_end</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">S</span><span class="plain-syntax"> != </span><span class="identifier-syntax">E</span><span class="plain-syntax">) &amp;&amp; (</span><a href="2-tw2.html#SP2" class="function-link"><span class="function-syntax">Wiring::wired_to</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">) != </span><span class="identifier-syntax">E</span><span class="plain-syntax">)) </span><a href="2-tw2.html#SP5" class="function-link"><span class="function-syntax">Wiring::wire_to</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">, </span><span class="identifier-syntax">E</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>&#167;7. Wiring to names.</b>It is also possible to say that a symbol has a meaning whose location is not
yet known &mdash; we can't have <span class="extract"><span class="extract-syntax">A ~~&gt; B</span></span> because we don't know where <span class="extract"><span class="extract-syntax">B</span></span> is, and
maybe it does not even exist yet. All we know is that it will have a given
name, <span class="extract"><span class="extract-syntax">T</span></span>. In this case, we write <span class="extract"><span class="extract-syntax">A ~~&gt; "ogron"</span></span> to say that <span class="extract"><span class="extract-syntax">A</span></span> should one
day be wired to a <span class="extract"><span class="extract-syntax">B</span></span> called <span class="extract"><span class="extract-syntax">"ogron"</span></span>.
</p>

<p class="commentary">This is used mainly for plugs (see below), but also as a convenience when
reading Inter files in text format, since it enables forward references to be
made.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Wiring::wire_to_name</span><button class="popup" onclick="togglePopup('usagePopup6')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup6">Usage of <span class="code-font"><span class="function-syntax">Wiring::wire_to_name</span></span>:<br/><a href="2-tw2.html#SP14">&#167;14</a><br/>Symbols Tables - <a href="2-st.html#SP20">&#167;20</a><br/>Inter in Binary Files - <a href="3-iibf.html#SP10_1_3_2_2">&#167;10.1.3.2.2</a><br/>Inter in Text Files - <a href="3-iitf.html#SP5_1">&#167;5.1</a><br/>The Plug Construct - <a href="6-tpc.html#SP2">&#167;2</a><br/>The Socket Construct - <a href="6-tsc.html#SP2">&#167;2</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">S</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">T</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">S</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"null symbol cannot be wired"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-sym.html#SP10" class="function-link"><span class="function-syntax">InterSymbol::is_metadata_key</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">)) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"metadata keys cannot be wired"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Str::len</span><span class="plain-syntax">(</span><span class="identifier-syntax">T</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"symbols cannot be wired to the empty name"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-tw2.html#SP5" class="function-link"><span class="function-syntax">Wiring::wire_to</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">S</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">wiring</span><span class="plain-syntax">.</span><span class="element-syntax">wants_to_connect_to</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Str::duplicate</span><span class="plain-syntax">(</span><span class="identifier-syntax">T</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Wiring::is_wired_to_name</span><button class="popup" onclick="togglePopup('usagePopup7')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup7">Usage of <span class="code-font"><span class="function-syntax">Wiring::is_wired_to_name</span></span>:<br/>Symbols Tables - <a href="2-st.html#SP20">&#167;20</a><br/>Inter in Text Files - <a href="3-iitf.html#SP5_1">&#167;5.1</a>, <a href="3-iitf.html#SP7">&#167;7</a><br/>The Plug Construct - <a href="6-tpc.html#SP3">&#167;3</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">S</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">S</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">Str::len</span><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">wiring</span><span class="plain-syntax">.</span><span class="element-syntax">wants_to_connect_to</span><span class="plain-syntax">) &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="function-syntax">Wiring::wired_to_name</span><button class="popup" onclick="togglePopup('usagePopup8')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup8">Usage of <span class="code-font"><span class="function-syntax">Wiring::wired_to_name</span></span>:<br/><a href="2-tw2.html#SP15">&#167;15</a><br/>Symbols Tables - <a href="2-st.html#SP20">&#167;20</a><br/>Transmigration - <a href="2-trn.html#SP5_2_2_2">&#167;5.2.2.2</a><br/>Inter in Binary Files - <a href="3-iibf.html#SP10_2_3_2_2">&#167;10.2.3.2.2</a><br/>Inter in Text Files - <a href="3-iitf.html#SP5_1">&#167;5.1</a>, <a href="3-iitf.html#SP7_1">&#167;7.1</a><br/>The Plug Construct - <a href="6-tpc.html#SP3">&#167;3</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">S</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">S</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">S</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">wiring</span><span class="plain-syntax">.</span><span class="element-syntax">wants_to_connect_to</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP8" class="paragraph-anchor"></a><b>&#167;8. Plugs and sockets.</b>Now suppose a symbol in package <span class="extract"><span class="extract-syntax">X</span></span> wants to refer to a meaning which
does not yet exist, and will in fact never exist in the current tree. (It will
be linked in from another tree later on.) For example, perhaps Inform 7 is
compiling a function body which needs to refer to <span class="extract"><span class="extract-syntax">CreatePV</span></span>, a function
in BasicInformKit.
</p>

<p class="commentary">This is done by having <span class="extract"><span class="extract-syntax">CreatePV</span></span> in <span class="extract"><span class="extract-syntax">X</span></span> wire to a special symbol called
a "plug" in a special package of the tree at <span class="extract"><span class="extract-syntax">/main/connectors</span></span>.
(See <a href="../building-module/1-ls.html" class="internal">Large-Scale Structure (in building)</a> for more on this package.) That plug
is left dangling, in the sense that it is wired to the name <span class="extract"><span class="extract-syntax">"CreatePV"</span></span>,
but that this name is unresolved.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">MAIN</span><span class="plain-syntax"> </span><span class="identifier-syntax">TREE</span>
<span class="plain-syntax">    +-----------------+      +--------------------------+</span>
<span class="plain-syntax">    | </span><span class="identifier-syntax">Package</span><span class="plain-syntax"> </span><span class="identifier-syntax">X</span><span class="plain-syntax">       |      | </span><span class="identifier-syntax">Package</span><span class="plain-syntax"> /</span><span class="identifier-syntax">main</span><span class="plain-syntax">/</span><span class="identifier-syntax">connectors</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    |                 |      |                          |</span>
<span class="plain-syntax">    | </span><span class="identifier-syntax">CreatePV</span><span class="plain-syntax"> ~~~~~~~~~~~~~~~&gt; </span><span class="identifier-syntax">_plug_BlkValueCreate</span><span class="plain-syntax"> ~~~~~~~&gt; </span><span class="string-syntax">"CreatePV"</span>
<span class="plain-syntax">    +-----------------+      +--------------------------+</span>
</pre>
<p class="commentary">Meanwhile, suppose a second tree holds <a href="../BasicInformKit/index.html" class="internal">BasicInformKit</a>. This looks like so:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">BASICINFORMKIT</span><span class="plain-syntax"> </span><span class="identifier-syntax">TREE</span>
<span class="plain-syntax">    +-------------------+      +--------------------------+</span>
<span class="plain-syntax">    | </span><span class="identifier-syntax">Package</span><span class="plain-syntax"> </span><span class="identifier-syntax">Y</span><span class="plain-syntax">         |      | </span><span class="identifier-syntax">Package</span><span class="plain-syntax"> /</span><span class="identifier-syntax">main</span><span class="plain-syntax">/</span><span class="identifier-syntax">connectors</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    |                   |      |                          |</span>
<span class="plain-syntax">    | </span><span class="identifier-syntax">CreatePV</span><span class="plain-syntax"> &lt;~~~~~~~~~~~~~~~~ </span><span class="identifier-syntax">CreatePV</span><span class="plain-syntax"> &lt;~~~~~~~~~~~~~~~~~~ </span><span class="string-syntax">"CreatePV"</span>
<span class="plain-syntax">    | .....             |      +--------------------------+</span>
<span class="plain-syntax">    | </span><span class="identifier-syntax">function</span><span class="plain-syntax"> </span><span class="identifier-syntax">defn</span><span class="plain-syntax">     |</span>
<span class="plain-syntax">    | </span><span class="identifier-syntax">of</span><span class="plain-syntax"> </span><span class="identifier-syntax">CreatePV</span><span class="plain-syntax">       |</span>
<span class="plain-syntax">    | </span><span class="identifier-syntax">function</span><span class="plain-syntax"> </span><span class="identifier-syntax">defn</span><span class="plain-syntax">     |</span>
<span class="plain-syntax">    | </span><span class="identifier-syntax">of</span><span class="plain-syntax"> </span><span class="identifier-syntax">SecretFunction</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    +-------------------+</span>
</pre>
<p class="commentary">Package <span class="extract"><span class="extract-syntax">Y</span></span> in this tree holds two function definitions, let's say: <span class="extract"><span class="extract-syntax">CreatePV</span></span>
and <span class="extract"><span class="extract-syntax">SecretFunction</span></span>. The latter is private to BasicInformKit, in that the linking
process in <a href="../pipeline-module/index.html" class="internal">pipeline</a> does not allow symbols in other trees to be wired to it.
But <span class="extract"><span class="extract-syntax">CreatePV</span></span> is available. That is because the BasicInformKit provides
a "socket" to it.
</p>

<p class="commentary">Sockets, like plugs, live only in the <span class="extract"><span class="extract-syntax">/main/connectors</span></span> package of a tree.
A typical tree will have both plugs and sockets; note that no plug will ever
have the same symbol name as any socket, because all plug names begin <span class="extract"><span class="extract-syntax">_plug_...</span></span>
and no socket names do.
</p>

<p class="commentary firstcommentary"><a id="SP9" class="paragraph-anchor"></a><b>&#167;9. </b>The point of this is that after <a href="2-trn.html" class="internal">Transmigration</a> there will be a single
tree like so, which has merged the connectors from the two original trees,
and which now contains both <span class="extract"><span class="extract-syntax">X</span></span> and <span class="extract"><span class="extract-syntax">Y</span></span>. We can npw connect the plug
<span class="extract"><span class="extract-syntax">_plug_BlkValueCreate</span></span> with the socket <span class="extract"><span class="extract-syntax">CreatePV</span></span>:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">.. </span><span class="identifier-syntax">MERGED</span><span class="plain-syntax"> </span><span class="identifier-syntax">TREE</span><span class="plain-syntax"> ................................................</span>
<span class="plain-syntax">.  +-----------------+      +--------------------------+      .</span>
<span class="plain-syntax">.  | </span><span class="identifier-syntax">Package</span><span class="plain-syntax"> </span><span class="identifier-syntax">X</span><span class="plain-syntax">       |      | </span><span class="identifier-syntax">Package</span><span class="plain-syntax"> /</span><span class="identifier-syntax">main</span><span class="plain-syntax">/</span><span class="identifier-syntax">connectors</span><span class="plain-syntax"> |      .</span>
<span class="plain-syntax">.  |                 |      |                          |      .</span>
<span class="plain-syntax">.  | </span><span class="identifier-syntax">CreatePV</span><span class="plain-syntax"> ~~~~~~~~~~~~~~&gt; </span><span class="identifier-syntax">_plug_BlkValueCreate</span><span class="plain-syntax"> ~~~~~~~\   .</span>
<span class="plain-syntax">.  +-----------------+      |                          |   \  .</span>
<span class="plain-syntax">.                           |                          |    | .</span>
<span class="plain-syntax">.  +-----------------+      |                          |    | .</span>
<span class="plain-syntax">.  | </span><span class="identifier-syntax">Package</span><span class="plain-syntax"> </span><span class="identifier-syntax">Y</span><span class="plain-syntax">       |      |                          |    | .</span>
<span class="plain-syntax">.  |                 |      |                          |   /  .</span>
<span class="plain-syntax">.  | </span><span class="identifier-syntax">CreatePV</span><span class="plain-syntax"> &lt;~~~~~~~~~~~~~~~ </span><span class="identifier-syntax">CreatePV</span><span class="plain-syntax"> &lt;~~~~~~~~~~~~~~~~~/   .</span>
<span class="plain-syntax">.  | .....           |      +--------------------------+      .</span>
<span class="plain-syntax">.  | </span><span class="identifier-syntax">function</span><span class="plain-syntax"> </span><span class="identifier-syntax">defn</span><span class="plain-syntax">   |                                        .</span>
<span class="plain-syntax">.  +-----------------+                                        .</span>
<span class="plain-syntax">...............................................................</span>
</pre>
<p class="commentary">The cable end from <span class="extract"><span class="extract-syntax">CreatePV</span></span> in <span class="extract"><span class="extract-syntax">X</span></span> is indeed the definition in <span class="extract"><span class="extract-syntax">Y</span></span>,
and all is well.
</p>

<p class="commentary">Some sockets may never be used &mdash; that would be a situation where one tree
offers a meaning as being available to other trees, but where nobody takes
up the offer. The only essential thing is that all plugs must find a socket.
</p>

<p class="commentary firstcommentary"><a id="SP10" class="paragraph-anchor"></a><b>&#167;10. </b>Note the following consequences of this design:
</p>

<ul class="items"><li>&#9679; Every socket is always wired.
</li><li>&#9679; Every plug is either wired to a socket, or to a name, in the hope that
it will one day be wired to a socket of that name.
</li><li>&#9679; All uses of, say, <span class="extract"><span class="extract-syntax">CreatePV</span></span> in the main tree are wired to a single
plug in its <span class="extract"><span class="extract-syntax">/main/connectors</span></span> package.
</li><li>&#9679; By looking at the incoming count of a plug or socket, we can see if it is
still needed &mdash; if the count falls to 0, it is not.
</li><li>&#9679; Connecting plugs to sockets is relatively fast, because only one package's
symbols table needs to be searched &mdash; <span class="extract"><span class="extract-syntax">/main/connectors</span></span>.
</li><li>&#9679; Each tree can offer any number of meanings to other trees, but they are
identified by name only. If two packages in a tree both define functions called
<span class="extract"><span class="extract-syntax">hulke</span></span>, then they cannot both be "exported" in this way, because the connectors
package can only contain one socket with the name <span class="extract"><span class="extract-syntax">hulke</span></span>.
</li><li>&#9679; But the flip side of that is that a tree wanting a meaning in some other
tree does not need to know the Inter hierarchy structure of that other tree,
or even its identity. This is a little like linking functions in C: a file
of object code can refer to <span class="extract"><span class="extract-syntax">mystery_distant_function()</span></span> without any idea of
where that will come from.
</li></ul>
<p class="commentary firstcommentary"><a id="SP11" class="paragraph-anchor"></a><b>&#167;11. </b>To start with something simple: finding if a tree has a socket with a given
identifier name.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="function-syntax">Wiring::find_socket</span><button class="popup" onclick="togglePopup('usagePopup9')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup9">Usage of <span class="code-font"><span class="function-syntax">Wiring::find_socket</span></span>:<br/><a href="2-tw2.html#SP16">&#167;16</a><br/>Transmigration - <a href="2-trn.html#SP3_5_1">&#167;3.5.1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">name</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_package</span><span class="plain-syntax"> *</span><span class="identifier-syntax">connectors</span><span class="plain-syntax"> = </span><span class="identifier-syntax">LargeScale::connectors_package_if_it_exists</span><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_symbols_table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">CT</span><span class="plain-syntax"> = </span><a href="2-pck.html#SP10" class="function-link"><span class="function-syntax">InterPackage::scope</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">connectors</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">connectors</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">S</span><span class="plain-syntax"> = </span><a href="2-st.html#SP8" class="function-link"><span class="function-syntax">InterSymbolsTable::symbol_from_name_not_following</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">CT</span><span class="plain-syntax">, </span><span class="identifier-syntax">name</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-sym.html#SP13" class="function-link"><span class="function-syntax">InterSymbol::is_socket</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">S</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP12" class="paragraph-anchor"></a><b>&#167;12. </b>Now suppose our tree defines a meaning with a symbol <span class="extract"><span class="extract-syntax">defn</span></span>, and we want to
offer that for the potential use of other trees. We call this function to create
a socket for it: the return value is a socket <span class="extract"><span class="extract-syntax">S</span></span> for which <span class="extract"><span class="extract-syntax">S ~~&gt; defn</span></span>.
</p>

<p class="commentary">It is legal to call this more than once on the same <span class="extract"><span class="extract-syntax">defn</span></span> and the same <span class="extract"><span class="extract-syntax">name</span></span>,
in which case the second time does nothing, but it is an error to inconsistently
claim that <span class="extract"><span class="extract-syntax">name</span></span> means two different symbols.
</p>

<p class="commentary">Note that during <a href="2-trn.html" class="internal">Transmigration</a> there is a brief period when a socket in
one tree is wired to a socket in another; this is the only time a socket can
be wired to another connector.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="function-syntax">Wiring::socket</span><button class="popup" onclick="togglePopup('usagePopup10')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup10">Usage of <span class="code-font"><span class="function-syntax">Wiring::socket</span></span>:<br/>Transmigration - <a href="2-trn.html#SP3_5_1">&#167;3.5.1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">name</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">defn</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><a href="2-tw2.html#SP12" class="function-link"><span class="function-syntax">Wiring::socket_inner</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">name</span><span class="plain-syntax">, </span><span class="identifier-syntax">defn</span><span class="plain-syntax">, </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
<span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="function-syntax">Wiring::socket_one_per_name_only</span><span class="plain-syntax">(</span><span class="reserved-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">name</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">defn</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><a href="2-tw2.html#SP12" class="function-link"><span class="function-syntax">Wiring::socket_inner</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">name</span><span class="plain-syntax">, </span><span class="identifier-syntax">defn</span><span class="plain-syntax">, </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
<span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="function-syntax">Wiring::socket_inner</span><span class="plain-syntax">(</span><span class="reserved-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">name</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">defn</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">allow_multiple_sockets_with_the_same_name</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">defn</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"tried to make socket for nothing"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-sym.html#SP13" class="function-link"><span class="function-syntax">InterSymbol::is_socket</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">defn</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">I</span><span class="plain-syntax"> == </span><a href="2-pck.html#SP4" class="function-link"><span class="function-syntax">InterPackage::tree</span></a><span class="plain-syntax">(</span><a href="2-sym.html#SP3" class="function-link"><span class="function-syntax">InterSymbol::package</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">defn</span><span class="plain-syntax">))) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">STDERR</span><span class="plain-syntax">, </span><span class="string-syntax">"Socket '%S' ~~&gt; socket "</span><span class="plain-syntax">, </span><span class="identifier-syntax">name</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="2-st.html#SP18" class="function-link"><span class="function-syntax">InterSymbolsTable::write_symbol_URL</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">STDERR</span><span class="plain-syntax">, </span><span class="identifier-syntax">defn</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">STDERR</span><span class="plain-syntax">, </span><span class="string-syntax">" ~~&gt; "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="2-st.html#SP18" class="function-link"><span class="function-syntax">InterSymbolsTable::write_symbol_URL</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">STDERR</span><span class="plain-syntax">, </span><a href="2-tw2.html#SP3" class="function-link"><span class="function-syntax">Wiring::cable_end</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">defn</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">STDERR</span><span class="plain-syntax">, </span><span class="string-syntax">"\n"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"tried to make socket for another socket in the same tree"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-tw2.html#SP2" class="function-link"><span class="function-syntax">Wiring::is_wired</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">defn</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">STDERR</span><span class="plain-syntax">, </span><span class="string-syntax">"Socket %S ~~&gt; "</span><span class="plain-syntax">, </span><span class="identifier-syntax">name</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="2-st.html#SP18" class="function-link"><span class="function-syntax">InterSymbolsTable::write_symbol_URL</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">STDERR</span><span class="plain-syntax">, </span><span class="identifier-syntax">defn</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">STDERR</span><span class="plain-syntax">, </span><span class="string-syntax">" ~~&gt; "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="2-st.html#SP18" class="function-link"><span class="function-syntax">InterSymbolsTable::write_symbol_URL</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">STDERR</span><span class="plain-syntax">, </span><a href="2-tw2.html#SP3" class="function-link"><span class="function-syntax">Wiring::cable_end</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">defn</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">STDERR</span><span class="plain-syntax">, </span><span class="string-syntax">"\n"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"tried to make socket for wired symbol"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_package</span><span class="plain-syntax"> *</span><span class="identifier-syntax">connectors</span><span class="plain-syntax"> = </span><span class="identifier-syntax">LargeScale::ensure_connectors_package</span><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_symbols_table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">CT</span><span class="plain-syntax"> = </span><a href="2-pck.html#SP10" class="function-link"><span class="function-syntax">InterPackage::scope</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">connectors</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">socket</span><span class="plain-syntax"> = </span><a href="2-st.html#SP8" class="function-link"><span class="function-syntax">InterSymbolsTable::symbol_from_name_not_following</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">CT</span><span class="plain-syntax">, </span><span class="identifier-syntax">name</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">socket</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-sym.html#SP13" class="function-link"><span class="function-syntax">InterSymbol::is_socket</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">socket</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"tried to make socket with same name as a plug"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">allow_multiple_sockets_with_the_same_name</span><span class="plain-syntax"> == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">            (</span><a href="2-tw2.html#SP2" class="function-link"><span class="function-syntax">Wiring::wired_to</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">socket</span><span class="plain-syntax">) != </span><span class="identifier-syntax">defn</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">STDERR</span><span class="plain-syntax">, </span><span class="string-syntax">"Socket %S has two defns\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">name</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="2-st.html#SP18" class="function-link"><span class="function-syntax">InterSymbolsTable::write_symbol_URL</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">STDERR</span><span class="plain-syntax">, </span><a href="2-tw2.html#SP2" class="function-link"><span class="function-syntax">Wiring::wired_to</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">socket</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">STDERR</span><span class="plain-syntax">, </span><span class="string-syntax">"\n"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="2-st.html#SP18" class="function-link"><span class="function-syntax">InterSymbolsTable::write_symbol_URL</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">STDERR</span><span class="plain-syntax">, </span><span class="identifier-syntax">defn</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">STDERR</span><span class="plain-syntax">, </span><span class="string-syntax">"\n"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"tried to make inconsistent socket"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">socket</span><span class="plain-syntax"> = </span><a href="2-st.html#SP11" class="function-link"><span class="function-syntax">InterSymbolsTable::create_with_unique_name</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">CT</span><span class="plain-syntax">, </span><span class="identifier-syntax">name</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="2-tw2.html#SP13" class="function-link"><span class="function-syntax">Wiring::make_socket_to</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">socket</span><span class="plain-syntax">, </span><span class="identifier-syntax">defn</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">INTER_CONNECTORS</span><span class="plain-syntax">, </span><span class="string-syntax">"Socket $3 ~~&gt; $3\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">socket</span><span class="plain-syntax">, </span><span class="identifier-syntax">defn</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">socket</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP13" class="paragraph-anchor"></a><b>&#167;13. </b>Which uses this function, to change an existing symbol into a socket. It
should only be used immediately after the symbol has been created.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Wiring::make_socket_to</span><button class="popup" onclick="togglePopup('usagePopup11')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup11">Usage of <span class="code-font"><span class="function-syntax">Wiring::make_socket_to</span></span>:<br/><a href="2-tw2.html#SP12">&#167;12</a><br/>Inter in Text Files - <a href="3-iitf.html#SP7_1">&#167;7.1</a><br/>The Plug Construct - <a href="6-tpc.html#SP2">&#167;2</a><br/>The Socket Construct - <a href="6-tsc.html#SP2">&#167;2</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">S</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">defn</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><a href="2-tw2.html#SP5" class="function-link"><span class="function-syntax">Wiring::wire_to</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">, </span><span class="identifier-syntax">defn</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-sym.html#SP13" class="function-link"><span class="function-syntax">InterSymbol::make_socket</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP14" class="paragraph-anchor"></a><b>&#167;14. </b>And similarly for plugs:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="function-syntax">Wiring::plug</span><button class="popup" onclick="togglePopup('usagePopup12')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup12">Usage of <span class="code-font"><span class="function-syntax">Wiring::plug</span></span>:<br/>Transmigration - <a href="2-trn.html#SP5_2_2_2">&#167;5.2.2.2</a>, <a href="2-trn.html#SP5_2_2_3">&#167;5.2.2.3</a>, <a href="2-trn.html#SP6_1">&#167;6.1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">wanted</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_package</span><span class="plain-syntax"> *</span><span class="identifier-syntax">connectors</span><span class="plain-syntax"> = </span><span class="identifier-syntax">LargeScale::ensure_connectors_package</span><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_symbols_table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">CT</span><span class="plain-syntax"> = </span><a href="2-pck.html#SP10" class="function-link"><span class="function-syntax">InterPackage::scope</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">connectors</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">name</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">name</span><span class="plain-syntax">, </span><span class="string-syntax">"_plug_%S"</span><span class="plain-syntax">, </span><span class="identifier-syntax">wanted</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">plug</span><span class="plain-syntax"> = </span><a href="2-st.html#SP8" class="function-link"><span class="function-syntax">InterSymbolsTable::symbol_from_name_not_following</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">CT</span><span class="plain-syntax">, </span><span class="identifier-syntax">name</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">plug</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-sym.html#SP13" class="function-link"><span class="function-syntax">InterSymbol::is_plug</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">plug</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"tried to make plug with same name as a socket"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">plug</span><span class="plain-syntax"> = </span><a href="2-st.html#SP11" class="function-link"><span class="function-syntax">InterSymbolsTable::create_with_unique_name</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">CT</span><span class="plain-syntax">, </span><span class="identifier-syntax">name</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="2-tw2.html#SP14" class="function-link"><span class="function-syntax">Wiring::make_plug_wanting_identifier</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">plug</span><span class="plain-syntax">, </span><span class="identifier-syntax">wanted</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">INTER_CONNECTORS</span><span class="plain-syntax">, </span><span class="string-syntax">"Plug $3 ~~&gt; \"%S\"\n"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">plug</span><span class="plain-syntax">, </span><a href="2-tw2.html#SP15" class="function-link"><span class="function-syntax">Wiring::name_sought_by_loose_plug</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">plug</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">name</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">plug</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Wiring::make_plug_wanting_identifier</span><button class="popup" onclick="togglePopup('usagePopup13')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup13">Usage of <span class="code-font"><span class="function-syntax">Wiring::make_plug_wanting_identifier</span></span>:<br/>The Plug Construct - <a href="6-tpc.html#SP2">&#167;2</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">S</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">wanted</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><a href="2-tw2.html#SP7" class="function-link"><span class="function-syntax">Wiring::wire_to_name</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">, </span><span class="identifier-syntax">wanted</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-sym.html#SP13" class="function-link"><span class="function-syntax">InterSymbol::make_plug</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP15" class="paragraph-anchor"></a><b>&#167;15. </b>An unwired plug &mdash; i.e., wired to a name but not to an actual symbol &mdash; is
said to be "loose".
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Wiring::is_loose_plug</span><button class="popup" onclick="togglePopup('usagePopup14')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup14">Usage of <span class="code-font"><span class="function-syntax">Wiring::is_loose_plug</span></span>:<br/><a href="2-tw2.html#SP16">&#167;16</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">S</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><a href="2-sym.html#SP13" class="function-link"><span class="function-syntax">InterSymbol::is_plug</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">)) &amp;&amp; (</span><a href="2-tw2.html#SP2" class="function-link"><span class="function-syntax">Wiring::is_wired</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="function-syntax">Wiring::name_sought_by_loose_plug</span><button class="popup" onclick="togglePopup('usagePopup15')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup15">Usage of <span class="code-font"><span class="function-syntax">Wiring::name_sought_by_loose_plug</span></span>:<br/><a href="2-tw2.html#SP14">&#167;14</a>, <a href="2-tw2.html#SP16">&#167;16</a>, <a href="2-tw2.html#SP17">&#167;17</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">S</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-tw2.html#SP15" class="function-link"><span class="function-syntax">Wiring::is_loose_plug</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><a href="2-tw2.html#SP7" class="function-link"><span class="function-syntax">Wiring::wired_to_name</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP16" class="paragraph-anchor"></a><b>&#167;16. </b>And here at last is the connection:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Wiring::connect_plugs_to_sockets</span><span class="plain-syntax">(</span><span class="reserved-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_package</span><span class="plain-syntax"> *</span><span class="identifier-syntax">connectors</span><span class="plain-syntax"> = </span><span class="identifier-syntax">LargeScale::connectors_package_if_it_exists</span><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">connectors</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">inter_symbols_table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">ST</span><span class="plain-syntax"> = </span><a href="2-pck.html#SP10" class="function-link"><span class="function-syntax">InterPackage::scope</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">connectors</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOOP_OVER_SYMBOLS_TABLE</span><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">, </span><span class="identifier-syntax">ST</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-tw2.html#SP15" class="function-link"><span class="function-syntax">Wiring::is_loose_plug</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">name</span><span class="plain-syntax"> = </span><a href="2-tw2.html#SP15" class="function-link"><span class="function-syntax">Wiring::name_sought_by_loose_plug</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">socket</span><span class="plain-syntax"> = </span><a href="2-tw2.html#SP11" class="function-link"><span class="function-syntax">Wiring::find_socket</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">name</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">socket</span><span class="plain-syntax">) </span><a href="2-tw2.html#SP16" class="function-link"><span class="function-syntax">Wiring::wire_plug</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">, </span><span class="identifier-syntax">socket</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">last_tick</span><span class="plain-syntax"> = -1;</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">Str::len</span><span class="plain-syntax">(</span><span class="identifier-syntax">name</span><span class="plain-syntax">); </span><span class="identifier-syntax">i</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">                        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Str::get_at</span><span class="plain-syntax">(</span><span class="identifier-syntax">name</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">) == </span><span class="character-syntax">'`'</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                            </span><span class="identifier-syntax">last_tick</span><span class="plain-syntax"> = </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                        }</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">last_tick</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">Str::prefix_eq</span><span class="plain-syntax">(</span><span class="identifier-syntax">name</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"implied`"</span><span class="plain-syntax">, </span><span class="constant-syntax">8</span><span class="plain-syntax">)) ||</span>
<span class="plain-syntax">                            (</span><span class="identifier-syntax">Str::prefix_eq</span><span class="plain-syntax">(</span><span class="identifier-syntax">name</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"main`"</span><span class="plain-syntax">, </span><span class="constant-syntax">5</span><span class="plain-syntax">))) {</span>
<span class="plain-syntax">                            </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">N</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                            </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">NS</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                            </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=8; </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">last_tick</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">                                </span><span class="identifier-syntax">PUT_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">NS</span><span class="plain-syntax">, </span><span class="identifier-syntax">Str::get_at</span><span class="plain-syntax">(</span><span class="identifier-syntax">name</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">));</span>
<span class="plain-syntax">                            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Str::eq</span><span class="plain-syntax">(</span><span class="identifier-syntax">NS</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"main"</span><span class="plain-syntax">)) </span><span class="identifier-syntax">Str::clear</span><span class="plain-syntax">(</span><span class="identifier-syntax">NS</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                            </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=</span><span class="identifier-syntax">last_tick</span><span class="plain-syntax">+1; </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">Str::len</span><span class="plain-syntax">(</span><span class="identifier-syntax">name</span><span class="plain-syntax">); </span><span class="identifier-syntax">i</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">                                </span><span class="identifier-syntax">PUT_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">N</span><span class="plain-syntax">, </span><span class="identifier-syntax">Str::get_at</span><span class="plain-syntax">(</span><span class="identifier-syntax">name</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">));</span>
<span class="plain-syntax">                            </span><span class="identifier-syntax">socket</span><span class="plain-syntax"> = </span><a href="2-tw2.html#SP11" class="function-link"><span class="function-syntax">Wiring::find_socket</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">N</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">socket</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                                </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">INTER_CONNECTORS</span><span class="plain-syntax">, </span><span class="string-syntax">"Wire implied plug '%S' to socket with global name: $3\n"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                                    </span><span class="identifier-syntax">name</span><span class="plain-syntax">, </span><span class="identifier-syntax">S</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                                </span><a href="2-tw2.html#SP16" class="function-link"><span class="function-syntax">Wiring::wire_plug</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">, </span><span class="identifier-syntax">socket</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                            }</span>
<span class="plain-syntax">                            </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">N</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                            </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">NS</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                        }</span>
<span class="plain-syntax">                    }</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Wiring::wire_plug</span><span class="plain-syntax">(</span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">plug</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">to</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">plug</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"no plug"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-sym.html#SP13" class="function-link"><span class="function-syntax">InterSymbol::is_socket</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">to</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"not a socket"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">INTER_CONNECTORS</span><span class="plain-syntax">, </span><span class="string-syntax">"Plug $3 ~~&gt; socket $3\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">plug</span><span class="plain-syntax">, </span><span class="identifier-syntax">to</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-tw2.html#SP5" class="function-link"><span class="function-syntax">Wiring::wire_to</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">plug</span><span class="plain-syntax">, </span><span class="identifier-syntax">to</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP17" class="paragraph-anchor"></a><b>&#167;17. </b>For debugging:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Wiring::log_connectors</span><span class="plain-syntax">(</span><span class="reserved-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"Connectors in tree %d:\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">allocation_id</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOG_INDENT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_package</span><span class="plain-syntax"> *</span><span class="identifier-syntax">connectors</span><span class="plain-syntax"> = </span><span class="identifier-syntax">LargeScale::connectors_package_if_it_exists</span><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">connectors</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">inter_symbols_table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">T</span><span class="plain-syntax"> = </span><a href="2-pck.html#SP10" class="function-link"><span class="function-syntax">InterPackage::scope</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">connectors</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">T</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"package with no symbols"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOOP_OVER_SYMBOLS_TABLE</span><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">, </span><span class="identifier-syntax">T</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-sym.html#SP13" class="function-link"><span class="function-syntax">InterSymbol::is_socket</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"Socket (%dx ~~&gt;) $3 ~~&gt; $3\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">S</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">wiring</span><span class="plain-syntax">.</span><span class="element-syntax">incoming_wire_count</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">S</span><span class="plain-syntax">, </span><a href="2-tw2.html#SP2" class="function-link"><span class="function-syntax">Wiring::wired_to</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-sym.html#SP13" class="function-link"><span class="function-syntax">InterSymbol::is_plug</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-tw2.html#SP2" class="function-link"><span class="function-syntax">Wiring::is_wired</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"Wired plug (%dx ~~&gt;) $3 ~~&gt; $3\n"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                        </span><span class="identifier-syntax">S</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">wiring</span><span class="plain-syntax">.</span><span class="element-syntax">incoming_wire_count</span><span class="plain-syntax">, </span><span class="identifier-syntax">S</span><span class="plain-syntax">, </span><a href="2-tw2.html#SP2" class="function-link"><span class="function-syntax">Wiring::wired_to</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">));</span>
<span class="plain-syntax">                } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"Loose plug (%dx ~~&gt;) $3 ~~&gt; \"%S\"\n"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                        </span><span class="identifier-syntax">S</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">wiring</span><span class="plain-syntax">.</span><span class="element-syntax">incoming_wire_count</span><span class="plain-syntax">, </span><span class="identifier-syntax">S</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                        </span><a href="2-tw2.html#SP15" class="function-link"><span class="function-syntax">Wiring::name_sought_by_loose_plug</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">));</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">            } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"Anomalous $3\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">S</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOG_OUTDENT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="2-ann.html">&#10094;</a></li><li class="progresschapter"><a href="P-wtmd.html">P</a></li><li class="progresschapter"><a href="1-bm.html">1</a></li><li class="progresscurrentchapter">2</li><li class="progresssection"><a href="2-it.html">it</a></li><li class="progresssection"><a href="2-in.html">in</a></li><li class="progresssection"><a href="2-bkm.html">bkm</a></li><li class="progresssection"><a href="2-np.html">np</a></li><li class="progresssection"><a href="2-tw.html">tw</a></li><li class="progresssection"><a href="2-pck.html">pck</a></li><li class="progresssection"><a href="2-inl.html">inl</a></li><li class="progresssection"><a href="2-st.html">st</a></li><li class="progresssection"><a href="2-sym.html">sym</a></li><li class="progresssection"><a href="2-ann.html">ann</a></li><li class="progresscurrent">tw2</li><li class="progresssection"><a href="2-trn.html">trn</a></li><li class="progresschapter"><a href="3-ic.html">3</a></li><li class="progresschapter"><a href="4-tcc.html">4</a></li><li class="progresschapter"><a href="5-tac.html">5</a></li><li class="progresschapter"><a href="6-tpc.html">6</a></li><li class="progressnext"><a href="2-trn.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

